/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhnb
 * Date: 2011-6-3 下午03:00:39
 */
package com.telnet;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;


public class StartSocket {
    
    /**
     * 启动扫描
     * @param exeSev                    线程池及执行者对象
     * @param waitTime                  线程池执行者超时（秒）
     * @param ipAddr                    IP地址（IP4，如：127.0.0.1）
     * @param startPort                 起扫端口
     * @param endPort                   终扫端口
     * @param timeout                   Socket扫描超时（毫秒）
     * @return                          扫描结果集
     * @throws InterruptedException     
     */
    public Object[] start(ExecutorService exeSev, int waitTime, String ipAddr, int startPort, int endPort, int timeout) throws InterruptedException{
        
        Object[] returnValue = null;
        
        for (int i = startPort; i <= endPort; i++) {
            exeSev.execute(new ScannerBySocket(ipAddr,i,timeout));
        }
        
        System.out.println("please wait for Thread-pool completed.");
        exeSev.awaitTermination(waitTime, TimeUnit.SECONDS);
        
        returnValue = ScannerBySocket.ports.toArray();
        
        return returnValue;
    }
    
    /**
     * 已扫描成功的端口信息
     * @return
     */
    public String getPortInfo(){
        return ScannerBySocket.getInfo();
    }

}
